﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wq.Application;
using Wq.Framework.Base.Admin;
using Wq.ManagerService.Models;
using Wq.Model;

namespace Wq.Manager.API
{
    /// <summary>
    /// 管理接口
    /// </summary>
    [Route("admin")]
    public class ManagerController : ManagerBaseController
    {
        private readonly ManagerApplication managerApplication;

        /// <summary>
        /// 管理接口
        /// </summary>
        /// <param name="managerApplication"></param>
        public ManagerController(ManagerApplication managerApplication) => this.managerApplication = managerApplication;

        #region 权限组

        /// <summary>
        /// 添加权限组
        /// </summary>
        /// <param name="role">权限实体</param>
        /// <returns></returns>
        [HttpPost("role/save")]
        public IActionResult SaveRole(RoleEditor role)
        {
            managerApplication.SaveRole(role);
            return SuccessResult();
        }

        /// <summary>
        /// 获取权限组
        /// </summary>
        /// <param name="id">权限Id</param>
        /// <returns></returns>

        [HttpGet("role/details")]
        public IActionResult GetRole(long id) => SuccessResult(managerApplication.Details(id));

        /// <summary>
        /// 获取全部权限组
        /// </summary>
        /// <returns></returns>
        [HttpPost("role/list")]
        public IActionResult GetRoles() => SuccessResult(managerApplication.GetRoles());

        /// <summary>
        /// 获取用户导航列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("role/menus")]
        public IActionResult GetUsableMenus() => SuccessResult(managerApplication.GetUsableMenus(CurrentManager));


        /// <summary>
        /// 删除权限组
        /// </summary>
        /// <param name="id">管理员Id</param>
        /// <returns></returns>
        [HttpGet("role/delete")]
        public IActionResult DeleteRole(long id)
        {
            managerApplication.DeleteRole(id);
            return SuccessResult();
        }
        #endregion

        #region 管理员
        /// <summary>
        /// 管理员列表
        /// </summary>
        /// <param name="pageModel">查询条件</param>
        /// <returns></returns>
        [HttpPost("manager/list")]
        public IActionResult List(PageModel<ManagerQuery> pageModel) => SuccessResult(managerApplication.List(pageModel));

        /// <summary>
        /// 添加编辑管理员
        /// </summary>
        /// <param name="manager">管理员实体</param>
        /// <returns></returns>
        [HttpPost("manager/save")]

        public IActionResult SaveManager(ManagerEditor manager)
        {
            managerApplication.SaveManager(manager);
            return SuccessResult();
        }

        /// <summary>
        /// 删除管理员
        /// </summary>
        /// <param name="id">管理员Id</param>
        /// <returns></returns>
        [HttpDelete("manager/{id}")]
        public IActionResult RemoveManager(long id)
        {
            managerApplication.RemoveManager(id);
            return SuccessResult();
        }
        #endregion

    }
}
